package com.example.demo.common.vo;

import com.example.demo.common.enums.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author ccubee
 * @since 20-7-18 13:00
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultVo {

    private Integer code;

    private String msg;

    private Object data;


    public static ResultVo success(){
        return new ResultVo(ResultEnum.OK.getCode(), ResultEnum.OK.getMsg(), null);
    }

    public static ResultVo success(Object data){
        return new ResultVo(ResultEnum.OK.getCode(), ResultEnum.OK.getMsg(), data);
    }

    public static ResultVo isFail(){
        return new ResultVo(ResultEnum.FAIL.getCode(), ResultEnum.FAIL.getMsg(), null);
    }
    public static ResultVo isFail(String msg){
        return new ResultVo(ResultEnum.FAIL.getCode(), msg, null);
    }

    public ResultVo(Integer code) {
        setCode(code);
        setMsg(ResultEnum.of(code).getMsg());
    }
}
